package edu.guigu.viewmodeldemo;

import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import edu.guigu.viewmodeldemo.databinding.FragmentMyFragment1Binding;

public class MyFragment1 extends Fragment {

    private FragmentMyFragment1Binding binding;

    public static MyFragment1 newInstance() {
        return new MyFragment1();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
//        View view = inflater.inflate(R.layout.fragment_my_fragment1, container, false);
        binding = FragmentMyFragment1Binding.inflate(inflater, container, false);
        UserViewModel viewModel = new ViewModelProvider(getActivity()).get(UserViewModel.class);

        viewModel.user.setName("张三");
        viewModel.user.setAge(20);

        TextView tvName = binding.tvName;
        tvName.setText( viewModel.user.getName() );

        return binding.getRoot();
    }

}